<script lang="ts" setup>
import { ref, onUpdated } from "vue";

const data = ref({
  time: 0,
  foots: 0,
  long: 0,
});

const isUpdated = ref(false);

onUpdated(() => {
  isUpdated.value = true;
});

const updateData = () => {
  data.value.time = 68;
  data.value.foots = 11896;
  data.value.long = 7.96;
};
</script>
<template>
  <div class="container">
    <button @click="updateData" class="update-btn">
      <i class="fas fa-sync-alt"></i> 更新数据
    </button>

    <div class="data-card">
      <div class="data-item">
        <i class="fas fa-clock data-icon"></i>
        <div class="data-content">
          <h3 class="data-label">运动时长</h3>
          <p class="data-value" :class="{ updated: isUpdated }">
            {{ data.time }} 分钟
          </p>
        </div>
      </div>

      <div class="data-item">
        <i class="fas fa-walking data-icon"></i>
        <div class="data-content">
          <h3 class="data-label">行走步数</h3>
          <p class="data-value" :class="{ updated: isUpdated }">
            {{ data.foots }} 步
          </p>
        </div>
      </div>

      <div class="data-item">
        <i class="fas fa-route data-icon"></i>
        <div class="data-content">
          <h3 class="data-label">运动距离</h3>
          <p class="data-value" :class="{ updated: isUpdated }">
            {{ data.long }} 公里
          </p>
        </div>
      </div>
    </div>
  </div>
</template>
<style scoped>
.container {
  max-width: 800px;
  margin: 2rem auto;
  padding: 0 1rem;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

.update-btn {
  background-color: #3b82f6;
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.3s ease;
  margin: 0 auto 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.update-btn:hover {
  background-color: #2563eb;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.update-btn:active {
  transform: translateY(0);
}

.data-card {
  background-color: #ffffff;
  border-radius: 16px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05),
    0 8px 10px -6px rgba(0, 0, 0, 0.02);
  padding: 2rem;
}

.data-item {
  display: flex;
  align-items: center;
  padding: 1.25rem 0;
  border-bottom: 1px solid #f1f5f9;
  transition: transform 0.3s ease;
}

.data-item:last-child {
  border-bottom: none;
}

.data-item:hover {
  transform: translateX(5px);
}

.data-icon {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  margin-right: 1.5rem;
  font-size: 1.5rem;
}

.data-item:nth-child(1) .data-icon {
  background-color: rgba(59, 130, 246, 0.1);
  color: #3b82f6;
}

.data-item:nth-child(2) .data-icon {
  background-color: rgba(16, 185, 129, 0.1);
  color: #10b981;
}

.data-item:nth-child(3) .data-icon {
  background-color: rgba(245, 158, 11, 0.1);
  color: #f59e0b;
}

.data-label {
  font-size: 1rem;
  color: #64748b;
  margin: 0 0 0.25rem 0;
  font-weight: 500;
}

.data-value {
  font-size: 1.5rem;
  font-weight: 600;
  color: #1e293b;
  margin: 0;
  transition: all 0.5s ease;
}

.data-value.updated {
  animation: pulse 0.6s ease-in-out;
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
    color: #1e293b;
  }
  50% {
    transform: scale(1.05);
    color: #3b82f6;
  }
}

@media (max-width: 640px) {
  .data-card {
    padding: 1.5rem;
  }

  .data-item {
    padding: 1rem 0;
  }

  .data-icon {
    width: 40px;
    height: 40px;
    font-size: 1.25rem;
  }

  .data-value {
    font-size: 1.25rem;
  }
}
</style>
